package com.hex.liyue.giftmodule.presenter;

import com.alibaba.fastjson.JSONArray;
import com.hex.liyue.commonmodule.bean.BaseBean;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.giftmodule.bean.MyGiftsResultBean;

/**
 * Created by WJ on 2016/6/24.
 */
public class GiveAwayGiftsPresenter {
    private IGiveAwayGiftsView iGiveAwayGiftsView;

    public GiveAwayGiftsPresenter(IGiveAwayGiftsView iGiveAwayGiftsView) {
        this.iGiveAwayGiftsView = iGiveAwayGiftsView;
    }

    /**
     * 获取我的礼物
     */
    public void requestGetMyGiftList() {
        HttpManager.getInstance().myGiftList(UserManager.getUserId(), new ResponseListener<MyGiftsResultBean>() {
            @Override
            public void onSuccess(MyGiftsResultBean myGiftsResultBean) {
                iGiveAwayGiftsView.closeLod();
                iGiveAwayGiftsView.setAdapter(myGiftsResultBean);
            }

            @Override
            public void onFailure(String responseresult) {
                iGiveAwayGiftsView.closeLod();
            }
        });
    }

    public void sendGift(String to_uid, String appointment_id, JSONArray gift_list) {
        iGiveAwayGiftsView.showLod("加载中...");
        HttpManager.getInstance().sendGift(UserManager.getUserId(), to_uid, appointment_id, gift_list, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                iGiveAwayGiftsView.startInSomeDetailsActivity();
                iGiveAwayGiftsView.closeLod();
            }

            @Override
            public void onFailure(String responseresult) {
                iGiveAwayGiftsView.closeLod();
                iGiveAwayGiftsView.showT(responseresult);
            }
        });
    }
}
